<?php
/**
 * Created by PhpStorm.
 * User: Andy
 * Date: 2018/6/15
 * Time: 17:18
 */

namespace App\admin\controller;


class FileLock
{
    public function index(){
        $file = fopen(CACHE_PATH."test.txt","w+");

        // 排它性的锁定
        if (flock($file,LOCK_EX))
        {
            echo '开始休息';
            sleep(10);
            echo '休息结束';
            // release lock
            flock($file,LOCK_UN);
        }
        else
        {
            echo "Error locking file!";
        }

        fclose($file);
        echo 22;

    }

}